package com.example.house.vm

import androidx.lifecycle.MutableLiveData
import com.example.common.view.vm.BaseViewModel
import com.example.house.entity.House
import com.example.house.entity.People
import com.example.house.model.HouseRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel
class HouseViewModel @Inject constructor(private val repo:HouseRepository):BaseViewModel() {
    val mHouseSuccess = MutableLiveData<List<House>>()
    fun getHouse(id:Int){
        mViewModelScope.launch(mDispatcher){
            val (code,data,message) = repo.getHouse(id)
            if(code == 200){
                mHouseSuccess.postValue(data)
            }else{
                mError.postValue(message)
            }
        }
    }
    val mPeopleSuccess = MutableLiveData<List<People>>()
    fun getPeople(){
        mViewModelScope.launch(mDispatcher){
            val (code,data,message) = repo.getPeople()
            if(code == 200){
                mPeopleSuccess.postValue(data)
            }else{
                mError.postValue(message)
            }
        }
    }
}